
class CET4Scene extends Scene {
	private roleImage: eui.Image;
	private searchImage: eui.Image;
	private wordsImage: eui.Image;
	private listeningImage: eui.Image;
	private videoImage:eui.Image;
	private readingImage:eui.Image;
	private speakingImage:eui.Image;
	private returnImage: eui.Image;
	private searchLaterImage:eui.Image;
	private roleLaterImage:eui.Image;
	private setImage:eui.Image;
	private myhomeImage:eui.Image;
	private userSetImage:eui.Image;
	private taskImage:eui.Image;
	private ableImage:eui.Image;
	private retactImage:eui.Image;
	private searchText:eui.EditableText;
	private cet4bgImage:eui.Image;
	private myfriendImage:eui.Image;
	public static obj:any[];//用于存放单词

	public constructor() {
		super();
		this.addEventListener(egret.Event.ADDED_TO_STAGE,this.onAddToStage,this);
	}
	private urlloader:egret.URLLoader;//单词数据
    private onAddToStage(event:egret.Event)
    {
        this.urlloader = new egret.URLLoader();
        this.urlloader.dataFormat = egret.URLLoaderDataFormat.VARIABLES;
        var urlreq:egret.URLRequest = new egret.URLRequest();
        urlreq.url = "resource/words/CET4_words.json";//加载单词文件
        this.urlloader.load( urlreq );
        this.urlloader.addEventListener(egret.Event.COMPLETE, this.onComplete, this);
    }
    private onComplete(event:egret.Event):void//单词文件加载完成
    {
        var data=event.target.data;
        CET4Scene.obj=JSON.parse(data);//将json数据存放到数组
    }
	public onSkinLoaded() {
		this.returnImage.addEventListener(egret.TouchEvent.TOUCH_TAP, this.btnHandler, this);
		this.wordsImage.addEventListener(egret.TouchEvent.TOUCH_TAP, this.btnHandler, this);
		this.listeningImage.addEventListener(egret.TouchEvent.TOUCH_TAP, this.btnHandler, this);
		this.cet4bgImage.addEventListener(egret.TouchEvent.TOUCH_TAP, this.btnHandler, this);
		this.retactImage.addEventListener(egret.TouchEvent.TOUCH_TAP, this.btnHandler, this);
		this.ableImage.addEventListener(egret.TouchEvent.TOUCH_TAP, this.btnHandler, this);
		this.myfriendImage.addEventListener(egret.TouchEvent.TOUCH_TAP, this.btnHandler, this);
		this.roleImage.addEventListener(egret.TouchEvent.TOUCH_TAP, this.btnHandler, this);
		this.taskImage.addEventListener(egret.TouchEvent.TOUCH_TAP,this.btnHandler,this);
		this.searchImage.addEventListener(egret.TouchEvent.TOUCH_TAP, this.btnHandler, this);
		this.myhomeImage.addEventListener(egret.TouchEvent.TOUCH_TAP, this.btnHandler, this);
		this.userSetImage.addEventListener(egret.TouchEvent.TOUCH_TAP, this.btnHandler, this);
		this.setImage.addEventListener(egret.TouchEvent.TOUCH_TAP,this.btnHandler,this);
	}

	private btnHandler(evt: egret.TouchEvent) {
		let btnFocused = evt.currentTarget;        
		switch (btnFocused) {
			case this.cet4bgImage:
				if(btnFocused!=this.myhomeImage&&btnFocused!=this.userSetImage&&btnFocused!=this.taskImage&&btnFocused!=this.setImage){
						this.setImage.visible=false;
						this.myhomeImage.visible=false;
						this.userSetImage.visible=false;
						this.taskImage.visible=false;
						this.roleLaterImage.visible=false;
				}
				break;
			case this.returnImage:
				SceneManager.instance.removeScene(this);
				break;

			case this.listeningImage:
				//SceneManager.instance.removeScene(this);
				console.log("test");
				SceneManager.instance.addScene(new ListenListScene());
				break;
			case this.wordsImage:
				SceneManager.instance.addScene(new ReciteTask());
				break;
			case this.searchImage:	
				SceneManager.instance.addScene(new SearchScene());	
				break;
			case this.roleImage:
				
				if (this.roleLaterImage.visible == true) {
					
					this.roleLaterImage.visible = false;
					this.setImage.visible = false;
					this.myhomeImage.visible = false;
					this.userSetImage.visible = false;
					this.taskImage.visible = false;
				}
				
				//SceneManager.instance.addScene(new UserScene());
				else if (this.roleLaterImage.visible == false){
					this.roleLaterImage.visible = true;
					this.setImage.visible = true ;
					this.myhomeImage.visible = true;
					this.userSetImage.visible = true;
					this.taskImage.visible = true;

				}
				break ;
			case this.retactImage:
				this.ableImage.visible = true;
				this.wordsImage.visible = false;
				this.listeningImage.visible = false;
				this.videoImage.visible = false;
				this.readingImage.visible = false;
				this.speakingImage.visible = false;
				this.retactImage.visible = false;
				break;
			case this.ableImage:
				this.ableImage.visible = false;
				this.wordsImage.visible = true;
				this.listeningImage.visible = true;
				this.videoImage.visible = true;
				this.readingImage.visible = true;
				this.speakingImage.visible = true;
				this.retactImage.visible = true;
				break;

			case this.userSetImage://账号
				//if (this.userset.visible == true)
				SceneManager.instance.addScene(new UserScene());
				break;
			case this.myfriendImage:
				//SceneManager.instance.addScene(new FriendsWin());
				SceneManager.instance.addScene(new FriendsWin());
				break;
			case this.myhomeImage:
				SceneManager.instance.addScene(new myHome());
				break;
			case this.setImage:
				SceneManager.instance.addScene(new SetScene());
				break;
			case this.taskImage:
				SceneManager.instance.addScene(new TaskScene());
			
		}
	}

		private search_function(evt: egret.TouchEvent) {
		
			//	this.search_text.visible=false;
				if(this.roleLaterImage.visible==true)
					{
						this.searchLaterImage.visible=false;
					this.setImage.visible=false;
					this.myhomeImage.visible=false;
					this.userSetImage.visible=false;
					this.taskImage.visible=false;
					}
			
		}	
}


